from lin_base import *

def draw_RA_mark(draw,x0,y0,hour,minute,font=unicode_font_36,fgcolor=BLACK,lw=2):
    ra = hour + minute/60.0
    hour_show=hour % 24
    x= RA_to_x(x0,ra)
    y=y0
    #print('xy:',x,y)
    if minute==0:
        #print('draw long')
        draw.line([(x,y),(x,y+YM_LONG)],fill=fgcolor,width=lw)   
        #draw_text(im,'%02d' % hour_show, unicode_font_36,x,y+YM_TEXT,0)
        draw.text((x,y+YM_TEXT), text='%02d' % hour_show, font=font, fill=fgcolor)
    else:
        #print('draw short')
        draw.line([(x,y),(x,y+YM_SHORT)],fill=fgcolor,width=lw)   
    return x

def add_lin_RA(paper,title,x0,y0,font=unicode_font_36,
               fgcolor=BLACK):
    lw=2
    layer = paper.add_layer(name='RA')
    draw = layer.draw
    draw.text((x0-XM_TITLE,y0+YM_TEXT),title, font=font,fill=fgcolor)
    #draw.line([(x0,y0),(x0+int(100*MM_UNIT),y0+int(100*MM_UNIT))],fill=BLACK,width=lw) 
    hour=RA_START
    minute=0
    n=0
    while True:
        #print('hour:%d:%02d' % (hour,minute))
        xend=draw_RA_mark(draw,x0,y0,hour,minute,font=font)
        if minute==0 and n > RA_TOTAL:
            break
        minute+=10
        if minute==60:
            minute=0
            hour+=1
            n+=1
            #if n> RA_TOTAL:
            #    break
                
    draw.line([(x0,y0),(xend,y0)],fill=BLACK,width=2)
    return xend